#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = ["RunMsgServerCmd"]

import re

from com.mousechsh.common.cmd.MouseChshCmd import MouseChshCmd, mousechsh_cmd_annotation
from com.mousechsh.common.log.MouseChshLog import mousechsh_logging_exception
from com.mousechsh.common.middle.rpc.MouseChshRpcServer import mousechsh_rpc_server_runner


# from com.mousechsh.business.app.order.rpc.CheckTokenRpcFunc import CheckTokenRpcFunc

@mousechsh_cmd_annotation()
class RunMsgServerCmd(MouseChshCmd):

	def __init__(self):
		self._host = '0.0.0.0'
		self._port = 8001

	def reference(self):
		return [
			'com.mousechsh.business.app.msg.MouseChshMsgApi'
		]

	def command(self):
		return 'msg-server'

	def parse(self, *params):
		for item in params:
			if re.match('--host=', item):
				self._host = item[7:]
			elif re.match('--port=', item):
				self._port = item[7:]

	def run(self):
		try:
			self.object = mousechsh_rpc_server_runner(self._host, self._port)
		except Exception as ex:
			mousechsh_logging_exception(ex, "遇到无法恢复的错误：")

	def interrupt(self):
		server = self.object.get_object()
		server.close()
